<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>登陆</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1>登陆</h1>
    <form method="post" action="/user/login" id="loginForm">
        <p><input name="username" /><label for="username">用户名</label><p/>
        <p><input name="password" type="password" /><label for="password">密码</label><p/>
        <p><input type="submit" value="登陆" /><p/>
    </form>
    <script src="//upcdn.b0.upaiyun.com/libs/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#loginForm').submit(function() {
                var $this = $(this);
                $.ajax({
                    method:$this.attr('method'),
                    url:$this.attr('action'),
                    data:$this.serialize(),
                    dataType:'json'
                }).done(function(result) {
                    if (result.code == 0) {
                        return location.href = '/user/admin';
                    }
                    alert(result.msg || '服务器异常');
                }).fail(function() {
                    alert('网络异常');
                });
                return false;
            });
        });
    </script>
  </body>
</html>
